const roomCounts = {}; // 用于存储房间人数信息
const roomName = 'room1';

// 获取当前房间内的用户列表
const getUsersInRoom = (io, roomName) => {
    const clients = io.sockets.adapter.rooms.get(roomName);
    if (clients) {
        // console.log(clients);
        return Array.from(clients);
    } else {
        return [];
    }
};


// 更新房间人数信息函数
const updateRoomCounts = (roomName, change) => {
    if (!roomCounts[roomName]) {
        roomCounts[roomName] = 0;
    }
    roomCounts[roomName] += change;
    return roomCounts[roomName];
};

// 新用户加入房间，更新房间人数并广播
const updateAndBroadcastRoomCounts = (change) => {
    const currentCount = updateRoomCounts(roomName, change);
};

module.exports = { updateRoomCounts, updateAndBroadcastRoomCounts, getUsersInRoom };
